{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "\n",
    "\n",
    "def start():\n",
    "    os.system('cd D:\\\\ZIPS\\\\go-cqhttp_windows_amd64')\n",
    "    os.system('go-cqhttp.exe')\n",
    "\n",
    "\n",
    "start()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "发送GET /send_private_msg?user_id=1076451802&message=[CQ:face,id=307] HTTP/1.1\n",
      "Host:127.0.0.1:5700\n",
      "Connection: close\n",
      "\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import socket\n",
    "\n",
    "\n",
    "def send_msg(resp_dict: dict) -> int:\n",
    "    # 创建一个client socket:\n",
    "    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n",
    "    ip = '127.0.0.1'\n",
    "    # 建立连接:\n",
    "    client.connect((ip, 5700))\n",
    "\n",
    "    msg_type = resp_dict['msg_type']  # 回复类型（群聊/私聊）\n",
    "    number = resp_dict['number']  # 回复账号（群号/好友号）\n",
    "    msg = resp_dict['msg']  # 要回复的消息\n",
    "\n",
    "    # 将字符中的特殊字符进行url编码\n",
    "    msg = msg.replace(\" \", \"%20\")\n",
    "    msg = msg.replace(\"\\n\", \"%0a\")\n",
    "\n",
    "    if msg_type == 'group':\n",
    "        payload = \"GET /send_group_msg?group_id=\" + str(\n",
    "            number) + \"&message=\" + msg + \" HTTP/1.1\\r\\nHost:\" + ip + \":5700\\r\\nConnection: close\\r\\n\\r\\n\"\n",
    "    elif msg_type == 'private':\n",
    "        payload = \"GET /send_private_msg?user_id=\" + str(\n",
    "            number) + \"&message=\" + msg + \" HTTP/1.1\\r\\nHost:\" + ip + \":5700\\r\\nConnection: close\\r\\n\\r\\n\"\n",
    "    print(\"发送\" + payload)\n",
    "    # 发送数据:\n",
    "    client.send(payload.encode(\"utf-8\"))\n",
    "    client.close()\n",
    "    return 0\n",
    "\n",
    "send_msg({'msg_type':'private','number':1076451802,'msg':'[CQ:face,id=307]'})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "发送GET /send_private_msg?user_id=1076451802&message=[CQ:face,id=304] HTTP/1.1\n",
      "Host:127.0.0.1:5700\n",
      "Connection: close\n",
      "\n",
      "\n"
     ]
    }
   ],
   "source": [
    "import socket\n",
    "from datetime import datetime\n",
    "\n",
    "\n",
    "def send_msg(resp_dict: dict) -> int:\n",
    "    client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 创建一个client socket:\n",
    "    ip = '127.0.0.1'\n",
    "    client.connect((ip, 5700))# 建立连接:\n",
    "    number = resp_dict['number']  # 回复账号（群号/好友号）\n",
    "    msg = resp_dict['msg']  # 要回复的消息\n",
    "    msg = msg.replace(\" \", \"%20\").replace(\"\\n\", \"%0a\")# 将字符中的特殊字符进行url编码\n",
    "    payload = \"GET /send_private_msg?user_id=\" + \\\n",
    "        str(number) + \"&message=\" + msg + \" HTTP/1.1\\r\\nHost:\" + \\\n",
    "        ip + \":5700\\r\\nConnection: close\\r\\n\\r\\n\"\n",
    "    print(\"发送\" + payload)\n",
    "    client.send(payload.encode(\"utf-8\"))# 发送数据:\n",
    "    client.close()\n",
    "    return 0\n",
    "\n",
    "\n",
    "def send_on_time(h: int, m: int) -> None:\n",
    "    while True:\n",
    "        now = datetime.now()\n",
    "        if now.hour == h and now.minute == m:\n",
    "            send_msg({'number': 1076451802, 'msg': '[CQ:face,id=304]'})\n",
    "            break\n",
    "\n",
    "\n",
    "send_on_time(21, 32)\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.7 ('base')",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "42d820d8758cde2badbeb8f7eaaa44975ccec32144b366942c17254cc50801f8"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
